<template>
  <div class="view-fill">
    <div
      v-if="!assetDetailInfo.visible && !taskDetailsInfo.visible"
      class="app-container-flex"
    >
      <NewFullScreen
        v-model="showDialog"
        :title="title"
        :need-return="false"
        :btn-list="fullInfo.btnList"
        :needOperateAffair="true"
        :operateAffairData="affairTableInfo"
        @returnBack="returnBack"
      >
        <template v-slot:full-button>
          <el-button
            v-if="
              infoList.data.status === 4 &&
              $permission('assetInventoryPlan:confirm')
            "
            @click="confirmPlan"
            >确认</el-button
          >
          <el-button
            v-if="
              (infoList.data.status === 2 || infoList.data.status === 4) &&
              $permission('assetInventoryPlan:close')
            "
            @click="closePlan"
            >关闭</el-button
          >
          <el-button
            v-if="
              infoList.data.status === 2 &&
              $permission('assetInventoryPlan:revoke')
            "
            @click="revoke"
            >撤回</el-button
          >
        </template>
        <div id="table-list">
          <div class="model-panel">
            <div class="model-panel-title">
              <Tooltip :text="$t('basic_information')" />
            </div>
            <div class="model-panel-body">
              <basic-information :info="infoList" />
            </div>
          </div>

          <div id="table-box" class="model-panel">
            <el-tabs v-model="activeName" @tab-click="handleClick">
              <el-tab-pane label="盘点任务" name="first"></el-tab-pane>
              <el-tab-pane label="盘点资产" name="second"></el-tab-pane>
            </el-tabs>
            <div v-show="activeName === 'first'" class="model-panel-body">
              <!-- 条件栏 -->
              <div class="filter-wrapper">
                <new-page-filter
                  v-model:query="filterInfo.query.queryMap"
                  :query-more-json="true"
                  :filter-list="filterInfo.searchList"
                  :filter-btn="filterInfo.searchBtn"
                  :clear-type="clearType"
                >
                </new-page-filter>
                <div class="display-flex">
                  <el-button
                    v-if="
                      infoList.data.status === 2 || infoList.data.status === 4
                    "
                    @click="updateTaskUser('all')"
                    >修改盘点任务负责人</el-button
                  >
                  <el-button
                    v-if="
                      infoList.data.status === 2 || infoList.data.status === 4
                    "
                    @click="checkInventoryUser('all')"
                    >指定盘点人</el-button
                  >
                </div>
              </div>
              <div style="paddingbottom: 8px">
                <PopoverPrint
                  ref="popoverShow"
                  v-model:popoverVisible="popoverVisible"
                  :canPrint="$permission('assetInventoryPlan:printDetail')"
                  :templateArr="templateArr"
                  @tempClick="tempClick"
                  @print="print"
                ></PopoverPrint>
                <el-button
                  v-if="$permission('assetInventoryPlan:excelDetail')"
                  @click="exportExcel"
                  >导出excel</el-button
                >
              </div>

              <div class="flex_full_item">
                <!-- 表格 -->
                <page-table
                  v-model:data="tableInfo.data"
                  :pager="false"
                  :check-box="false"
                  :highlight-row="false"
                  :tab-index="true"
                  :field-list="tableInfo.fieldList"
                  :handle="tableInfo.handle"
                  @sortChange="sortChange"
                >
                  <template v-slot:col-orderNo="scope">
                    <span
                      class="slip-edit"
                      @click="showTasktDetail(scope.row)"
                      >{{ scope.row.orderNo }}</span
                    >
                  </template>
                </page-table>
              </div>
            </div>
            <div v-if="activeName === 'second'" class="model-panel-body">
              <!-- 条件栏 -->
              <new-page-filter
                v-model:query="taskFilterInfo.query.queryMap"
                :query-more-json="true"
                :filter-list="taskFilterInfo.searchList"
                :filter-btn="taskFilterInfo.searchBtn"
                :clear-type="taskClearType"
              >
              </new-page-filter>

              <div style="paddingbottom: 8px">
                <PopoverPrint
                  ref="popoverShow"
                  v-model:popoverVisible="popoverVisibleAsset"
                  :canPrint="$permission('assetInventoryPlan:printDetailList')"
                  :templateArr="templateAssetArr"
                  @tempClick="tempClickAsset"
                  @print="printDetail"
                ></PopoverPrint>
                <el-button
                  v-if="$permission('assetInventoryPlan:excelDetailList')"
                  @click="exportDetailExcel"
                  >导出excel</el-button
                >
              </div>

              <div class="flex_full_item">
                <!-- 表格 -->
                <page-table
                  v-model:data="taskTableInfo.data"
                  :pager="false"
                  :check-box="false"
                  :highlight-row="false"
                  :tab-index="true"
                  :field-list="taskTableInfo.fieldList"
                  @sortChange="taskSortChange"
                >
                  <template v-slot:col-preAssetName="scope">
                    <span
                      v-if="scope.row.inventoryStatus != '5'"
                      class="slip-edit"
                      @click="showAssetDetail(scope.row)"
                      >{{ scope.row.preAssetName }}</span
                    >
                    <span
                      v-else-if="scope.row.inventoryStatus == '5'"
                      class="slip-edit"
                      @click="showSurplusDetail(scope.row)"
                      >{{ scope.row.preAssetName }}</span
                    >
                    <span v-else>{{ scope.row.preAssetName }}</span>
                  </template>
                  <template v-slot:col-orderNo="scope">
                    <span>{{ scope.row.orderNo }}</span>
                  </template>
                  <template v-slot:col-inventoryPercent="scope">
                    <span>{{ scope.row.inventoryPercent || 0 }}%</span>
                  </template>
                </page-table>
              </div>
            </div>
          </div>
        </div>
      </NewFullScreen>
    </div>
    <!-- 详情页 -->
    <asset-card-detail
      v-if="assetDetailInfo.visible"
      :id="assetDetailInfo.id"
      v-model:visible="assetDetailInfo.visible"
      :title="assetDetailInfo.title"
    />
    <task-details
      v-if="taskDetailsInfo.visible"
      :id="taskDetailsInfo.id"
      v-model:visible="taskDetailsInfo.visible"
      :table-row-id="taskDetailsInfo.id"
      @returnBack="returnCallBack"
    />
    <SelectNoAuthUsers
      v-if="taskUserInfo.visible"
      v-model:show-dialog="taskUserInfo.visible"
      :api="taskUserInfo.api"
      :check-box="false"
      :highlight-row="true"
      @callback="selectTaskUser"
    />
    <SelectNoAuthUsers
      v-if="inventoryUserInfo.visible"
      v-model:show-dialog="inventoryUserInfo.visible"
      :api="inventoryUserInfo.api"
      :check-box="true"
      :checkedList="inventoryUserInfo.checkedList"
      :save-empty="true"
      :highlight-row="false"
      @callback="selectInventoryUser"
    />
    <page-dialog
      v-show="dialogInfo.visible"
      :title="dialogInfo.title"
      v-model:visible="dialogInfo.visible"
      :width="dialogInfo.width"
      :bt-loading="dialogInfo.btLoading"
      :bt-list="dialogInfo.btList"
    >
      <basic-information :info="surplusInfoList">
        <template v-slot:basic-assetUseDeptBusinessVOList>
          <dialog-table
            v-model:data="surplusInfoList.data.assetUseDeptBusinessVOList"
            :field-list="assetUseDeptTableInfo.fieldList"
            :pager="false"
            :check-box="false"
            :tab-index="true"
            :summary="false"
            :maxHeight="200"
          >
          </dialog-table>
        </template>
        <template v-slot:basic-assetCapitalSourceBusinessVOList>
          <dialog-table
            v-model:data="surplusInfoList.data.assetCapitalSourceBusinessVOList"
            :pager="false"
            :check-box="false"
            :tab-index="true"
            :summary="true"
            :summary-field-list="assetCapitalSourceTableInfo.summaryFieldList"
            :field-list="assetCapitalSourceTableInfo.fieldList"
            :maxHeight="200"
          >
          </dialog-table>
        </template>
      </basic-information>
    </page-dialog>
  </div>
</template>

<script setup>
import {
  getInventoryTaskOrderCustomizeListAll,
  getInventoryTaskOrderDetailCustomizeListAll,
  inventoryTaskOrderUpdateInventoryUser,
  closeInventoryTaskOrder,
  revokeInventoryOrderPlan,
  confirmInventoryOrderPlan,
  getInventoryOrderPlanById,
  closeInventoryOrderPlan,
  inventoryPlanOrderPrintOrder,
  inventoryPlanOrderExcelOrder,
  inventoryPlanOrderPrintOrderList,
  excelInventoryPlanDetailList,
  getInventorySurplusRecord,
} from '@/api/asset'
import { getCustomizeSetting } from '@/api/customize'
import { fatchTemplateByCode, getRrgUserList } from '@/api/base'
import { orderOpAffairAll } from '@/api/affair'
import { getCoreCodeStatus } from '@/api/core'
import _ from 'lodash'
import TaskDetails from '../assetInventoryTask/details'
import SelectNoAuthUsers from '@/components/SelectUsers/selectNoAuthUsers'
import { doPrint } from '@/utils/exportUtil.js'
import { selectByCodeAndDept } from '@/api/report.js'
import { updatePrintCount } from '@/api/mapping'
const AssetCardDetail = defineAsyncComponent(() =>
  import('@/views/asset/assetManage/assetCard/details')
)
const { proxy } = getCurrentInstance()
const emits = defineEmits()
const props = defineProps(['visible', 'title', 'tableRowId'])
const route = useRoute()

const activeName = ref('first')
// 过滤相关配置
const filterInfo = ref({
  sortArr: [],
  query: {
    sortString: '',
    customizeUserVO: {},
    queryMap: {
      planOrderId: {
        queryType: 'EQUALS',
        queryCategory: 'AND',
        value: props.tableRowId,
      },
    },
    queryParams: {
      taskStatusNotIn: 5,
    },
  },
  searchList: [],
  copyQueryMap: {},
  searchBtn: [
    { type: 'button', label: '搜索', event: search },
    { type: 'button', label: '重置', event: clearSearch },
  ],
})
const taskFilterInfo = ref({
  sortArr: [],
  query: {
    sortString: '',
    customizeUserVO: {},
    queryMap: {
      planOrderId: {
        queryType: 'EQUALS',
        queryCategory: 'AND',
        value: props.tableRowId,
      },
    },
    queryParams: {
      taskStatusNotIn: 5,
    },
  },
  searchList: [],
  copyQueryMap: {},
  searchBtn: [
    { type: 'button', label: '搜索', event: taskSearch },
    { type: 'button', label: '重置', event: taskClearSearch },
  ],
})
const infoList = ref({
  data: {},
  fieldList: [
    { label: '计划单号', value: 'orderNo' },
    { label: '计划名称', value: 'planName' },
    { label: '业务日期', value: 'businessDate' },
    { label: '状态', value: 'statusValue' },
    {
      label: '盘点位置',
      value: 'inventoryLocationValue',
    },
    { label: '计划负责人', value: 'planResponseUserName' },
    { label: '计划开始时间', value: 'planStartDate' },
    { label: '计划结束时间', value: 'planEndDate' },
    { label: '实际计划开始时间', value: 'inventoryStartDate' },
    { label: '实际计划结束时间', value: 'inventoryEndDate' },
    { label: '拆解维度', value: 'splitTypeValue' },
    { label: '盘点进度', value: 'inventoryPercent', type: 'progress' },
    { label: '应盘', value: 'inventoryQty' },
    { label: '待盘', value: 'pendInventoryQty' },
    { label: '相符', value: 'matchQty' },
    { label: '盘盈', value: 'surplusQty' },
    { label: '盘亏', value: 'lossQty' },
    { label: '创建人', value: 'createUserName' },
    { label: '创建时间', value: 'createTime' },
    { label: '备注', value: 'remark', type: 'popover' },
  ],
})
const affairTableInfo = ref({
  api: orderOpAffairAll,
  query: {
    orderType: 47,
    orderId: props.tableRowId,
    sort: 'operate_time desc',
  },
})
// 表格相关
const tableInfo = ref({
  ref: null,
  refresh: 1,
  initCurpage: 1,
  data: [],
  fieldList: [],
  handle: {
    fixed: 'right',
    label: '操作',
    width: '150',
    btList: [
      {
        label: '修改负责人',
        event: updateTaskUserSing,
        show: proxy.$permission('assetInventoryPlan:updateTaskResponseUser'),
        ifRender: function (row) {
          return [2, 1].includes(row.status)
        },
      },
      {
        label: '指定盘点人',
        event: checkInventoryUserSing,
        show: proxy.$permission('assetInventoryPlan:taskInventoryUser'),
        ifRender: function (row) {
          return [2, 1].includes(row.status)
        },
      },
      {
        label: '关闭',
        event: closeRow,
        show: proxy.$permission('assetInventoryPlan:close'),
        ifRender: function (row) {
          return [2, 1].includes(row.status)
        },
      },
    ],
  },
})
const taskTableInfo = ref({
  ref: null,
  refresh: 1,
  initCurpage: 1,
  copyData: [],
  isSysGroup: true,
  data: [],
  groupList: [], //合并项
  selections: [],
  fieldList: [],
})
const fullInfo = ref({
  btnList: [
    { value: 'button', type: 'slot' },
    { label: '返回', event: returnBack, show: true },
  ],
})
const assetDetailInfo = ref({
  visible: false,
  id: '',
  title: '资产详情',
})
const taskDetailsInfo = ref({
  visible: false,
  id: '',
})
const taskUserInfo = ref({
  visible: false,
  api: getRrgUserList,
  type: '',
  row: {},
})
const inventoryUserInfo = ref({
  visible: false,
  api: getRrgUserList,
  type: '',
  checkedList: [],
  row: {},
})
const surplusInfoList = ref({
  data: {},
  fieldList: [
    {
      label: '资产名称',
      value: 'assetName',
    },
    {
      label: '资产卡片号',
      value: 'assetCode',
      show: true,
    },
    {
      label: '规格',
      value: 'standard',
      show: true,
    },
    {
      label: '厂家名称',
      value: 'brandName',
    },
    {
      label: '品牌',
      value: 'mark',
    },
    {
      label: '医疗器械分类目录',
      value: 'deviceTypeValue',
    },
    {
      label: '临时采购',
      value: 'temporaryPurchValue',
    },
    {
      label: '供应商',
      value: 'supplierName',
    },
    {
      label: '产地',
      value: 'originPlace',
    },
    {
      label: '使用状态',
      value: 'useStatusValue',
    },
    {
      label: '计提标志',
      value: 'accrualMarkValue',
    },

    {
      label: '仓库',
      value: 'depotName',
      show: computed(() => {
        return infoList.value.data.inventoryLocation == 2
      }),
    },
    {
      label: '管理部门',
      value: 'manageDeptName',
    },
    {
      label: '增加方式',
      value: 'increaseTypeValue',
    },
    {
      label: '计量单位',
      value: 'unitName',
    },
    {
      label: '金额',
      value: 'primitiveOriginalAmount',
    },
    {
      label: '资产分类',
      value: 'classifyTypeValue',
    },
    {
      label: '设备标识',
      value: 'assetMarkValue',
    },
    {
      label: '使用人',
      value: 'useUserName',
      show: computed(() => {
        return infoList.value.data.inventoryLocation == 1
      }),
    },

    {
      label: '存放地点',
      value: 'location',
    },
    {
      label: '备注',
      value: 'remark',
    },
    {
      label: '使用部门',
      value: 'assetUseDeptBusinessVOList',
      type: 'slot',
      show: computed(() => {
        return infoList.value.data.inventoryLocation == 1
      }),
      className: 'not-br',
    },
    {
      label: '资金来源',
      value: 'assetCapitalSourceBusinessVOList',
      type: 'slot',
      className: 'not-br',
    },
  ],
})
//资金来源表格
const assetCapitalSourceTableInfo = ref({
  data: [],
  summaryFieldList: [
    { value: 'amount', formatter: proxy.$fn.TripartiteMethodAsset },
  ],
  fieldList: [
    {
      label: '资金来源',
      value: 'sourceName',
    },
    {
      label: '金额',
      value: 'amount',
    },
  ],
})
const assetUseDeptTableInfo = ref({
  data: [],
  fieldList: [
    { label: '部门', value: 'useDeptName' },
    {
      label: '占比(%)',
      value: 'rate',
      labelTip: '总值100%',
    },
  ],
})
const dialogInfo = ref({
  visible: false,
  title: '盘盈详情',
  btLoading: false,
  type: '',
  msg: '',
  width: '1000px',
  flag: 'page',
  btList: [{ label: '关闭', event: handleClose, show: true }],
})
const clearType = ref(true)
const taskClearType = ref(true)
const showDialog = computed({
  get() {
    return props.visible
  },
  set(newValue) {
    emits('update:visible', newValue) // 更新父组件visible
  },
})

setData()
function setData() {
  let obj = {
    statusValue: {
      label: '状态',
      value: 'statusValue',
      asValue: 'status',
      componentType: 'select-model',
      code: 'asset_inventory_task_status',
      show: false,
      hidden: true,
    },
    inventoryPercent: {
      label: '盘点进度',
      value: 'inventoryPercent',
      componentType: 'input',
      type: 'slot',
      show: false,
      hidden: true,
    },
  }
  tableInfo.value.fieldList = Object.values({
    ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
    ...proxy.$fn.deepClone(obj),
  })
  filterInfo.value.searchList = Object.values({
    ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
    ...proxy.$fn.deepClone(obj),
  })
  taskTableInfo.value.fieldList = Object.values({
    ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
    ...proxy.$fn.deepClone(obj),
  })
  taskFilterInfo.value.searchList = Object.values({
    ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
    ...proxy.$fn.deepClone(obj),
  })
  getCustomize()
  getAssetCustomize()
}
function handleClose() {
  dialogInfo.value.visible = false
}
function showTasktDetail(row) {
  taskDetailsInfo.value.visible = true
  taskDetailsInfo.value.id = row.id
}
function showSurplusDetail(row) {
  getInventorySurplusRecord({ taskOrderDetailId: row.id }).then((res) => {
    if (res && res.success) {
      getStatus()
      dialogInfo.value.visible = true
      surplusInfoList.value.data = res.data
    }
  })
}
function getStatus() {
  getCoreCodeStatus({ codeType: '7' }).then((res) => {
    surplusInfoList.value.fieldList.forEach((item) => {
      if (item.value === 'assetCode') {
        item.show = !res.data
      }
    })
  })
}
function updateTaskUserSing(row) {
  updateTaskUser('', row)
}
function updateTaskUser(type, row = undefined) {
  //修改盘点负责人
  if (type) {
    let list = tableInfo.value.data.filter(
      (item) => item.status === 1 || item.status === 2
    )
    if (!list.length) {
      proxy.$message({
        message: `盘点任务已处理完不能操作`,
        type: 'warning',
        duration: 3500,
        showClose: true,
      })
      return
    }
  }
  taskUserInfo.value.visible = true
  taskUserInfo.value.type = type ? 'all' : ''
  taskUserInfo.value.row = row
}
function selectTaskUser(data) {
  //盘点负责人返回
  updataUser(data, 'taskUser')
}
function checkInventoryUserSing(row) {
  checkInventoryUser('', row)
}
function checkInventoryUser(type, row = undefined) {
  //指定盘点人
  if (type) {
    let list = tableInfo.value.data.filter(
      (item) => item.status === 1 || item.status === 2
    )
    if (!list.length) {
      proxy.$message({
        message: `盘点任务已处理完不能操作`,
        type: 'warning',
        duration: 3500,
        showClose: true,
      })
      return
    }
  }
  inventoryUserInfo.value.visible = true
  inventoryUserInfo.value.type = type ? 'all' : ''
  inventoryUserInfo.value.checkedList = []
  if (row) {
    inventoryUserInfo.value.row = row
    let arr = row.taskInventoryUser.split(',')
    if (arr && arr.length) {
      arr.forEach((item) => {
        inventoryUserInfo.value.checkedList.push(Number(item))
      })
    }
  }
}
function selectInventoryUser(data) {
  updataUser(data, 'inventoryUser')
  //指定盘点人返回
}
function updataUser(data, type) {
  let ids = []
  let params = {
    ids: [],
  }
  if (type === 'taskUser') {
    if (data && data.id) {
      if (taskUserInfo.value.type === 'all') {
        let list = tableInfo.value.data.filter(
          (item) => item.status === 1 || item.status === 2
        )
        if (list.length) {
          ids = list.map((item) => item.id)
        }
      } else {
        ids = [taskUserInfo.value.row.id]
      }
      params.ids = ids
      params.taskResponseUser = data.id
    }
  } else if (type === 'inventoryUser') {
    if (inventoryUserInfo.value.type === 'all') {
      let list = tableInfo.value.data.filter(
        (item) => item.status === 1 || item.status === 2
      )
      if (list.length) {
        ids = list.map((item) => item.id)
      }
    } else {
      ids = [inventoryUserInfo.value.row.id]
    }
    params.ids = ids
    params.taskInventoryUser =
      data && data.length ? data.map((item) => item.id).toString() : ''
  }
  inventoryTaskOrderUpdateInventoryUser(params).then((res) => {
    if (res && res.success) {
      getList()
    }
  })
}
function handleClick(tab) {
  const name = tab.paneName
  if (name === 'first') {
    getList()
  } else if (name === 'second') {
    getAssetList()
  }
}
function closePlan() {
  //关闭
  closeInventoryOrderPlan(infoList.value.data.id).then((res) => {
    if (res && res.success) {
      getMain()
      if (activeName.value === 'first') {
        getList()
      } else if (activeName.value === 'second') {
        getAssetList()
      }
    }
  })
}
function revoke() {
  //撤回
  revokeInventoryOrderPlan([props.tableRowId]).then((res) => {
    if (res && res.success) {
      returnBack()
    }
  })
}
function closeRow(row) {
  //关闭单条任务
  closeInventoryTaskOrder(row.id).then((res) => {
    if (res && res.success) {
      getList()
    }
  })
}
function confirmPlan() {
  const data = infoList.value.data
  confirmInventoryOrderPlan(data.id).then((resp) => {
    if (resp && resp.success) {
      getMain()
      if (activeName.value === 'first') {
        getList()
      } else if (activeName.value === 'second') {
        getAssetList()
      }
    }
  })
}
function returnCallBack() {
  getMain()
  if (activeName.value === 'first') {
    getList()
  } else if (activeName.value === 'second') {
    getAssetList()
  }
}
function clearSearch() {
  clearType.value = !clearType.value
  filterInfo.value.query.queryMap = proxy.$fn.deepClone(
    filterInfo.value.copyQueryMap
  )
  search()
}
function taskClearSearch() {
  taskClearType.value = !taskClearType.value
  taskFilterInfo.value.query.queryMap = proxy.$fn.deepClone(
    taskFilterInfo.value.copyQueryMap
  )
  taskSearch()
}
function showAssetDetail(row) {
  assetDetailInfo.value.id = row.assetId
  assetDetailInfo.value.visible = true
}
function getList() {
  getInventoryTaskOrderCustomizeListAll(filterInfo.value.query).then((resp) => {
    if (resp && resp.success) {
      tableInfo.value.data = resp.data
    }
  })
}
function getAssetList() {
  getInventoryTaskOrderDetailCustomizeListAll(taskFilterInfo.value.query).then(
    (resp) => {
      if (resp && resp.success) {
        taskTableInfo.value.data = resp.data
      }
    }
  )
}
// 搜索
function search() {
  ////搜索
  getList()
}
function taskSearch() {
  getAssetList()
}
// 触发事件
function handleEvent(event, data) {
  switch (event) {
    case 'tableCheck':
      tableInfo.value.selections = [...data]
      break
  }
}
function returnBack() {
  //返回
  showDialog.value = false
  emits('returnBack')
}

const templateArr = ref([])
const templateAssetArr = ref([])
const popoverVisible = ref(false)
const popoverVisibleAsset = ref(false)
//打印
function print() {
  selectByCodeAndDept({
    tempCode: 'inventoryPlanOrderTaskDetail',
    deptId: infoList.value.data.deptId,
  }).then((res) => {
    if (res && res.success) {
      templateArr.value = res.data
      popoverVisible.value = true
      // 一条数据则直接打印
      if (templateArr.value.length === 1) {
        proxy.$refs.popoverShow.hidePopover()
        doPrint({
          name: templateArr.value[0].ureportName,
          params: {
            applicationId: infoList.value.data.id,
            orderId: infoList.value.data.id,
            orderNo: infoList.value.data.orderNo,
          },
          callback: printCallback,
          data: {},
        })
      }
    }
  })
}
function printCallback() {}
function tempClick(item) {
  doPrint({
    name: item.ureportName,
    params: {
      applicationId: infoList.value.data.id,
      orderId: infoList.value.data.id,
      orderNo: infoList.value.data.orderNo,
    },
    callback: printCallback,
    data: {},
  })
  popoverVisible.value = false
}
function tempClickAsset(item) {
  doPrint({
    name: item.ureportName,
    params: {
      applicationId: infoList.value.data.id,
      orderId: infoList.value.data.id,
      orderNo: infoList.value.data.orderNo,
    },
    callback: printCallback,
    data: {},
  })
  popoverVisibleAsset.value = false
}
function printDetail() {
  selectByCodeAndDept({
    tempCode: 'inventoryPlanOrderAssetDetail',
    deptId: infoList.value.data.deptId,
  }).then((res) => {
    if (res && res.success) {
      templateAssetArr.value = res.data
      popoverVisibleAsset.value = true
      // 一条数据则直接打印
      if (templateAssetArr.value.length === 1) {
        doPrint({
          name: templateAssetArr.value[0].ureportName,
          params: {
            applicationId: infoList.value.data.id,
            orderId: infoList.value.data.id,
            orderNo: infoList.value.data.orderNo,
          },
          callback: printCallback,
          data: {},
        })
      }
    }
  })
}
function getMain() {
  getInventoryOrderPlanById(props.tableRowId).then((resp) => {
    if (resp && resp.success) {
      let data = resp.data
      infoList.value.data = data

      if (infoList.value.data.inventoryLocation === 1) {
        taskTableInfo.value.fieldList.forEach((item) => {
          if (item.value === 'beforeDepotName') {
            item['hidden'] = true
          }
          if (item.value === 'depotName') {
            item['hidden'] = true
          }
          if (item.value === 'useDeptName') {
            item['hidden'] = false
          }
          if (item.value === 'beforeUseDeptName') {
            item['hidden'] = false
          }
        })
      } else if (infoList.value.data.inventoryLocation === 2) {
        taskTableInfo.value.fieldList.forEach((item) => {
          if (item.value === 'beforeDepotName') {
            item['hidden'] = false
          }
          if (item.value === 'depotName') {
            item['hidden'] = false
          }
          if (item.value === 'useDeptName') {
            item['hidden'] = true
          }
          if (item.value === 'beforeUseDeptName') {
            item['hidden'] = true
          }
        })
      }
    }
  })
}

function exportExcel() {
  let query = proxy.$fn.deepClone(filterInfo.value.query)
  //query.queryMap.inventoryResult.value = dialogInfo.value.flag.toString();
  inventoryPlanOrderExcelOrder(query).then((resp) => {
    if (resp) {
      proxy.$fn.parseExcel(resp)
    }
  })
}
function exportDetailExcel() {
  let query = proxy.$fn.deepClone(taskFilterInfo.value.query)
  //query.queryMap.inventoryResult.value = dialogInfo.value.flag.toString();
  excelInventoryPlanDetailList(query).then((resp) => {
    if (resp) {
      proxy.$fn.parseExcel(resp)
    }
  })
}
function sortChange(column) {
  if (filterInfo.value.query.customizeUserVO.head.sortType === 0) {
    let arr = proxy.$fn.sortChange(column, filterInfo.value.sortArr)
    filterInfo.value.sortArr = arr
    filterInfo.value.query.sortString = arr.length ? arr.toString() : ''
    getList()
  }
}
function taskSortChange(column) {
  if (taskFilterInfo.value.query.customizeUserVO.head.sortType === 0) {
    let arr = proxy.$fn.sortChange(column, taskFilterInfo.value.sortArr)
    taskFilterInfo.value.sortArr = arr
    taskFilterInfo.value.query.sortString = arr.length ? arr.toString() : ''
    getAssetList()
  }
}
function getCustomize() {
  let param = {
    tableKey:
      'assetAssetManageAssetInventoryPlanDetailTaskOrder-com.slip.spd.entity.vo.asset.AssetInventoryTaskOrderVO',
  }
  getCustomizeSetting(param).then((res) => {
    if (res && res.success) {
      let data = res.data
      filterInfo.value.query.customizeUserVO = data
      tableInfo.value.fieldList = proxy.$fn.setFieldList(
        tableInfo.value.fieldList,
        data.detail
      )
      let searchInfo = proxy.$fn.setSearchList(
        filterInfo.value.searchList,
        data.detail
      )
      filterInfo.value.query.queryMap = {
        ...searchInfo.queryMap,
        ...filterInfo.value.query.queryMap,
      }
      filterInfo.value.searchList = searchInfo.searchList
      filterInfo.value.searchList.forEach((item) => {
        item.event = search
      })
      filterInfo.value.copyQueryMap = proxy.$fn.deepClone(
        filterInfo.value.query.queryMap
      )
      if (props.tableRowId) {
        getMain()
        getList()
      }
    }
  })
}
function getAssetCustomize() {
  let param = {
    tableKey:
      'assetAssetManageAssetInventoryPlanAssetDetails-com.slip.spd.entity.vo.asset.AssetInventoryTaskOrderDetailVO',
  }
  getCustomizeSetting(param).then((res) => {
    if (res && res.success) {
      let data = res.data
      taskFilterInfo.value.query.customizeUserVO = data
      taskTableInfo.value.fieldList = proxy.$fn.setFieldList(
        taskTableInfo.value.fieldList,
        data.detail
      )
      let searchInfo = proxy.$fn.setSearchList(
        taskFilterInfo.value.searchList,
        data.detail
      )
      taskFilterInfo.value.query.queryMap = {
        ...searchInfo.queryMap,
        ...taskFilterInfo.value.query.queryMap,
      }
      taskFilterInfo.value.searchList = searchInfo.searchList
      taskFilterInfo.value.searchList.forEach((item) => {
        item.event = search
      })
      taskFilterInfo.value.copyQueryMap = proxy.$fn.deepClone(
        taskFilterInfo.value.query.queryMap
      )
    }
  })
}
</script>

<style scoped lang="scss">
:deep(.el-tabs) {
  .el-tabs__header {
    padding: 0 2px !important;
    box-sizing: border-box;
  }
  .el-tabs__nav-wrap::after {
    height: 1px !important;
  }
}
</style>
